//
//  XYJMainNavViewController.m
//  徙游记-01
//
//  Created by hcios on 2017/6/22.
//  Copyright © 2017年 鹿林. All rights reserved.
//

#import "XYJMainNavViewController.h"

@interface XYJMainNavViewController ()<UINavigationControllerDelegate>

@end

@implementation XYJMainNavViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    self.navigationBar.translucent = NO;
    // Do any additional setup after loading the view.
}




- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    //如果进入页面大于1，就会隐藏tabbar
    if (self.viewControllers.count >= 1) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        self.navigationBar.barStyle = UIBarStyleDefault;
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:@"%@",self.title] style:UIBarButtonItemStylePlain target:self action:@selector(downTabBarAnimation)];
        self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    }
    [super pushViewController:viewController animated:animated];
    
}


-(void)downTabBarAnimation{
    
    [UIView animateWithDuration:0.3 animations:^{
        self.view.frame = CGRectMake(self.view.frame.origin.x, 0 - 40, self.view.frame.size.width, self.view.frame.size.height);
    }];
}

#pragma mark --------navigation delegate
//该方法可以解决popRootViewController时tabbar的bug
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    //删除系统自带的tabBarButton
    for (UIView *tabBar in self.tabBarController.tabBar.subviews) {
        if ([tabBar isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [tabBar removeFromSuperview];
        }
    }
}

//电池栏信息高亮状态
-(UIStatusBarStyle)preferredStatusBarStyle{

    return UIStatusBarStyleLightContent;
}

@end
